package com.zy.drug.controller;

import java.util.ArrayList;
import java.util.List;

public class Test3 {

    public static ListNode reverseList(ListNode head) {
        // write your code here.
        List<Integer> temList = new ArrayList<>();
        while(head != null){
            temList.add(head.val);
            head = head.next;
        }
        ListNode  result2 = new ListNode(temList.get(temList.size()-1));
        ListNode  result = result2;
        for(int i = temList.size()-2;i >= 0; i--){
            ListNode subResult = new ListNode(temList.get(i));
            result.next = subResult;
            result = subResult;
        }
        return result2;
    }

    public static void main(String[] args) {
        ListNode head = new ListNode();
        head.val=1;
        head.next = new ListNode(2);
        ListNode listNode = reverseList(head);
        System.out.println(listNode.val);
        System.out.println(listNode.next.val);
    }
}
class ListNode {
    int val;
    ListNode next;
    ListNode() {}
    ListNode(int val) { this.val = val; }
    ListNode(int val, ListNode next) { this.val = val; this.next = next; }
}
